package com.budwk.app.jim.server;

import org.apache.commons.lang3.StringUtils;
import org.jim.core.ImChannelContext;
import org.jim.core.packets.LoginReqBody;
import org.jim.core.packets.LoginRespBody;
import org.jim.core.packets.User;
import org.jim.server.processor.login.LoginCmdProcessor;
import org.jim.server.protocol.AbstractProtocolCmdProcessor;

/**
 * @author ZY.Wang
 * @since 2023/6/14
 */
public class LoginServiceProcessor extends AbstractProtocolCmdProcessor implements LoginCmdProcessor {

    @Override
    public LoginRespBody doLogin(LoginReqBody loginReqBody, ImChannelContext imChannelContext) {
        String userId = loginReqBody.getUserId();
        String token = loginReqBody.getToken();
        if (StringUtils.isBlank(userId) || StringUtils.isBlank(token)) return LoginRespBody.failed();
        return LoginRespBody.success();
    }

    @Override
    public User getUser(LoginReqBody loginReqBody, ImChannelContext imChannelContext) {
        String userId = loginReqBody.getUserId();
        if (StringUtils.isBlank(userId)) return null;

        // JimJwtUserInfoBO userInfo = JimJwtTokenUtils.getInfoByToken(loginReqBody.getToken());
        // if (userInfo == null) return null;
        return User.newBuilder().userId(userId)
                .nick(loginReqBody.getPassword()).build();
    }

    @Override
    public void onSuccess(User user, ImChannelContext imChannelContext) {

    }

    @Override
    public void onFailed(ImChannelContext imChannelContext) {

    }
}
